check_login()
var params = new URLSearchParams(window.location.search);

var url_cardId = params.get('card_id'); 

window.onload = function() {
	
	


	showHead();
	showLeftMenu();

}

function serchOrder(page){
	getOrderList(page).then(function(data) {
		showOrderList(data,page);
	}).catch(function(error) {
		console.log(error);
	});
}
function showOrderList(data,page) {
	console.log(data)
	// 获取 <select> 元素的引用
	let selectElement = document.getElementById("order_list");
	selectElement.innerHTML = '';
	let str = '';
	// 使用循环创建选项并添加到 <select> 元素中
	for (let i = 0; i < data.length; i++) {
		
		if(data[i].status == 0){
			data[i].status = "未支付";
		}else if(data[i].status == 1){
			data[i].status = "已支付";
		}else if(data[i].status == 2){
			data[i].status = "已取消";
		}
		data[i].createTime = timestampToDatetime(data[i].createTime);
		str += `<tr role="row" class="odd">
					<td class="sorting_1" >
						<div class="form-check custom-checkbox ms-2">
							<input type="checkbox" class="form-check-input" id="CheckBox"
								required="" value="${data[i].id}">
							<label class="form-check-label" for="customCheckBox10"></label>
						</div>
					</td>
					<td>${data[i].realName}</td>
					<td class="">${data[i].cardId}</td>
					<td>${data[i].createTime}</td>
					<td>${data[i].orderName}</td>
				
					<td>
						<span class="badge light badge-danger">
							<i class="fa fa-circle text-danger me-1"></i>
							${data[i].status}
						</span>
					</td>
					<td>
						<div class="dropdown ms-auto ">
							<div class="btn-link" data-bs-toggle="dropdown" aria-expanded="false">
								<svg width="24px" height="24px" viewBox="0 0 24 24" version="1.1">
									<g stroke="none" stroke-width="1" fill="none" fill-rule="evenodd">
										<rect x="0" y="0" width="24" height="24"></rect>
										<circle fill="#000000" cx="5" cy="12" r="2"></circle>
										<circle fill="#000000" cx="12" cy="12" r="2"></circle>
										<circle fill="#000000" cx="19" cy="12" r="2"></circle>
									</g>
								</svg>
							</div>
							<div class="dropdown-menu dropdown-menu-end" style="margin: 0px;">
								<a class="dropdown-item" href="#">编辑</a>
								<a class="dropdown-item" href="#">删除</a>
								<a class="dropdown-item" href="#" onclick="showFrom(${data[i].id})">打印导检单</a>
							</div>
						</div>
					</td>
				</tr>`;
	}

	console.log(page)
	selectElement.innerHTML = str;
	let up = page-1;
	let down = page+1;
	let pageStr ='';
	if(up >=0){
		
		console.log("up"+up)
		 pageStr += `<a class="paginate_button" onclick="serchOrder(${up})">上一页</a>`;
	}
	
	if(down>=1){
		pageStr += `<a class="paginate_button next" onclick="serchOrder(${down})">下一页</a>`;
	}
	let pages = document.getElementById("pages");
	pages.innerHTML = '';
	console.log(pages)
	pages.innerHTML = pageStr
	console.log(selectElement)
}

function showFrom(id){
	
	getOrderInfo(id).then(function(data) {
		console.log(data)
		document.getElementById("fname").value = data.realName;
		document.getElementById("fcardId").value = data.cardId;
		document.getElementById("orderSn").value = data.orderSn;
		let tbody = document.getElementById("flist");
		let tbodyStr = '';
		for (var i = 0; i < data.projects.length; i++) {
			let j = i+1;
			tbodyStr +=`<tr>
							<td style="    padding: 0.7375rem 0.625rem;">${j}</td>
							<td style="    padding: 0.7375rem 0.625rem;">${data.projects[i].projectName}</td>
							<td style="    padding: 0.7375rem 0.625rem;"><span
									class="badge badge-primary">${data.projects[i].subjectName}</span>
							</td>
							
						</tr>`
			
			
		}
		tbody.innerHTML = tbodyStr;
		let qrcode = document.getElementById("qrcode")
		qrcode.setAttribute("src",data.qrcode)
		document.getElementById("fromModal").setAttribute("style","display:block")
		
		document.getElementById("fromModal").setAttribute("class","modal fade show")
		
	}).catch(function(error) {
		console.log(error);
	});
}

function closeFrom(){
	
	document.getElementById("fromModal").setAttribute("style","display:none")
	
	document.getElementById("fromModal").setAttribute("class","modal fade")
}